package main;

/**
 * Class that is representing a point on a plane.
 * 
 * @author Michal Stojek
 */
public class Point {
	public double x;
	public double y;
	
	/**
	 * Creates a new instance of a class Point with initial values (0, 0).
	 */
	public Point() {
		x = 0;
		y = 0;
	}
	
	/**
	 * Creates a new instance of a class Point with initial values (X, Y).
	 * 
	 * @param x	starting value of X of a point specified by (X, Y)
	 * @param y	starting value of Y of a point specified by (X, Y)
	 */
	public Point(double x, double y) {
		this.x = x;
		this.y = y;
	}
	
	public Point(java.awt.Point p) {
		x = p.x;
		y = p.y;
	}
	
	/**
	 * Returns an exact copy of the point that the method is called on.
	 * 
	 * @return copy of a point
	 */
	public Point copy() {		
		return new Point(x, y);
	}
	
	/**
	 * Returns value of X of a point specified by (X, Y).
	 * 
	 * @return value of X of a point specified by (X, Y)
	 */
	public double getX() {
		return x;
	}
	
	/**
	 * Sets value of X of a point specified by (X, Y).
	 * 
	 * @param x new value of X of a point specified by (X, Y)
	 */
	public void setX(double x) {
		this.x = x;
	}
	
	/**
	 * Returns value of Y of a point specified by (X, Y).
	 * 
	 * @return value of Y of a point specified by (X, Y)
	 */
	public double getY() {
		return y;
	}
	
	/**
	 * Sets value of Y of a point specified by (X, Y).
	 * 
	 * @param x new value of Y of a point specified by (X, Y)
	 */
	public void setY(double y) {
		this.y = y;
	}
	
	/**
	 * Returns a new Point that is the result of moving a point this method is being
	 * called on by a vector V.
	 * 
	 * @param v	vector V by which we are moving the point
	 * @return new point which is a result of moving a point this method is being
	 * called on by a vector V
	 */
	public Point moveBy(Vector v) {
		return new Point(x+v.getX(), y+v.getY());
	}
	
	/**
	 * Returns a {@link String} representation of a point in a format "(X, Y)".
	 * 
	 * @return {@link String} representation of a point in a format "(X, Y)"
	 */
	public String toString() {
		return "("+x+", "+y+")";
	}
	
	/**
	 * Returns a distance of a point this method is being called on from a {@link Line} l.
	 * 
	 * @param l	line from which we are measuring the distance
	 * @return a distance from a {@link Line} l
	 */
	public double distanceFrom(Line l) {
		return (Math.abs(l.getA()*x+l.getB()*y+l.getC())/Math.sqrt(l.getA()*l.getA()+l.getB()*l.getB()));
	}
	
	public double distanceFromPoint(Point p) {
		return (Math.sqrt(Math.pow(this.x-p.x, 2)+Math.pow(this.y-p.y, 2)));
	}
}
